package com.qifenqian.turbot.module.model

import android.content.Context

import com.qifenqian.turbot.base.BaseModel
import com.qifenqian.turbot.module.contract.RestaurantServiceContract
import com.qifenqian.turbot.module.entity.request.ServiceRequest
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantServiceEntity
import com.qifenqian.turbot.net.ModelCallback
import com.qifenqian.turbot.net.NetObserver

/**
 * @author H
 * @createTime 2018/12/26 15:48
 * @description
 * @see
 * @since
 */
class RestaurantServiceModel(context: Context) : BaseModel(context), RestaurantServiceContract.Model {

    override fun chooseService(request: ServiceRequest, callback: ModelCallback<Nothing>) {
        mClient!!.chooseService(request)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun deleteService(serviceId: Int, callback: ModelCallback<Nothing>) {
        mClient!!.deleteService(serviceId)
                .subscribe(object : NetObserver<Nothing>(mContext, true) {
                    override fun onSuccess(msg: String?, t: Nothing?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun addService(serviceName: String, callback: ModelCallback<RestaurantServiceEntity>) {
        mClient!!.addService(serviceName)
                .subscribe(object : NetObserver<RestaurantServiceEntity>(mContext, true) {
                    override fun onSuccess(msg: String?, t: RestaurantServiceEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getServiceList(callback: ModelCallback<List<RestaurantServiceEntity>>) {
        mClient!!.getServiceList()
                .subscribe(object : NetObserver<List<RestaurantServiceEntity>>(mContext, true) {
                    override fun onSuccess(msg: String?, t: List<RestaurantServiceEntity>?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }
}
